package com.glq1218.util;

import com.glq1218.domain.SortParam;

/**
 * @author glq1218
 */
public class SortUtils {
    public static String getSortSql(SortParam sortParam) {
        String sortField = humpToUnderline(sortParam.getSortField());
        return "ORDER BY " + sortField + ("descend".equals(sortParam.getSortOrder()) ? " DESC" : " ASC");
    }

    public static String humpToUnderline(String str) {
        String separator = "_";
        str = str.replaceAll("([a-z])([A-Z])", "$1" + separator + "$2").toLowerCase();
        return str;
    }
}
